<?php

namespace App\Http\Controllers\NB\common;

use Illuminate\Http\Request;
use DB;
use App\Http\Controllers\common\PublicController;

class ReportController extends PublicController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getIndex(Request $request)
    {
        /*代理商搜索始*/
        //获取自身及旗下所有代理商
        $agentInfo = $this -> agentInfo($request -> cookie('logon')['agent_id']);
        /*代理商搜索末*/
        //查询nb_report表
        $data = DB::table('nb_report') -> orderBy('addTime','desc')-> paginate(10);
        $get['agent_id'] = $this -> agent_id;
        //查询nb_type表
        $action = DB::table('nb_action') -> get();
        return view('NB.common.report.index',['data'=>$data,'action'=>$action,'agentInfo'=>$agentInfo,'get'=>$get,'request'=>$request->all()]);
    }

    public function postAction(Request $request){
        $info = $request -> except('_token');
        $data['manage'] = $request -> cookie('logon')['name'];
        //查询nb_action
        $data['action_name'] = DB::table('nb_action') -> select('name') -> where('id',$info['action_id']) -> first()['name'];
        $data['ht'] = time();
        //修改nb_report表
        $res = DB::table('nb_report') -> whereIn('id',$info['report_ids']) -> update($data);
        if($res){
            $status = 1;
        }else{
            $status = 0;
        }
        return $status;
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
